<div data-am-widget="tabs" class="am-tabs am-tabs-d2">
  <ul class="am-tabs-nav am-cf">
    <li class="am-active tab1"><a href="#">登录密码</a></li>
    <li class="tab2"><a href="#">取款密码</a></li>
  </ul>

  <div class="am-tabs-bd">
    <div class="am-tab-panel am-fade am-in am-active" id="tab1">
        <table class="center-table-form">
            <tr>
                <td class="label">原始密码：</td>
                <td class="field">
                    <input type="password" id="old" placeholder="输入原始密码" 
                            class="am-form-field" required/>
                </td>
                <td class="clue2">
                </td>
            </tr>
            <tr>
                <td class="label">新密码：</td>
                <td class="field">
                    <input type="password" id="password" placeholder="输入新的密码" 
                            class="am-form-field" required/>
                </td>
                <td class="clue2">
                    *请使用6-15位英文或数字的组合
                </td>
            </tr>
            <tr>
                <td class="label">确认密码：</td>
                <td class="field">
                    <input type="password" id="password2" placeholder="再次输入新的密码" data-equal-to="#password"
                            class="am-form-field" required/>
                </td>
                <td class="clue2">
                    *请再次输入新的登录密码
                </td>
            </tr>
        </table>
        <button class="center-form-button login-password-btn">修改</button>
  </div>

    <div class="am-tab-panel am-fade" id="tab2">
        <table class="center-table-form">
            <tr>
                <td class="label">旧取款密码：</td>
                <td class="field">
                    <input type="password" id="zf_password" placeholder="输入旧的取款密码" 
                            class="am-form-field"/>
                </td>
                <td class="clue2">
                    第一次设置取款密码，无需填写
                </td>
            </tr>
            <tr>
                <td class="label">新取款密码：</td>
                <td class="field">
                    <input type="password" id="zf_password2" placeholder="输入新的取款密码"
                            class="am-form-field" required/>
                </td>
                <td class="clue2">
                </td>
            </tr>
            <tr>
                <td class="label">确认密码：</td>
                <td class="field">
                    <input type="password" id="zf_password3" placeholder="再次输入新的取款密码"
                            class="am-form-field" required/>
                </td>
                <td class="clue2">
                </td>
            </tr>
        </table>
        <button class="center-form-button take-password-btn">修改</button>
    </div>
  </div>
</div>

<script>
    $(function() {
        $(".am-tabs .tab1").click(function() {
            $(".am-tabs").tabs('open', 0);
        });
        $(".am-tabs .tab2").click(function() {
            $(".am-tabs").tabs('open', 1);
        });
    });

    $(".login-password-btn").click(function() {
        var old = $("#old").val().trim(),
            p1 = $("#password").val().trim(),
            p2 = $("#password2").val().trim();
        if (old == '') {
            alert2("请填写原始密码！", true);
            return;
        }
        if (p1 == '') {
            alert2("请填写新的登录密码！", true);
            return;
        }
        if (p2 == '') {
            alert2("请再次输入新的登录密码！", true);
            return;
        }
        if (p1 != p2) {
            alert2("两次密码输入不一致！", true);
            return;
        }
        if (old == p1) {
            alert2("新密码不能和原始密码一样！", true);
            return;
        }
        if (!(/^[0-9a-zA-Z_]{5,14}$/.test(p1))) {
            alert2("新的登录密码不合法！", true);
            return;
        }

        startLoading();
        CMD.modify_password(p1, old, function() {
            stopLoading();
            alert2("密码修改成功！");
        }, function(message) {
            stopLoading();
            alert2(message || '密码修改失败！', true);
        });
    });

    $(".take-password-btn").click(function() {
        var old = $("#zf_password").val().trim(),
            p1 = $("#zf_password2").val().trim(),
            p2 = $("#zf_password3").val().trim();
        if (old != context.user.user.tpassword && context.user.user.tpassword) {
            alert2("旧取款密码错误！", true);
            return;
        }
        if (p1 == '') {
            alert2("请填写新的取款密码！", true);
            return;
        }
        if (p2 == '') {
            alert2("请再次输入新的取款密码！", true);
            return;
        }
        if (p1 != p2) {
            alert2("两次密码输入不一致！", true);
            return;
        }
        if (old == p1) {
            alert2("新密码不能和原始密码一样！", true);
            return;
        }

        startLoading();
        CMD.modify_user_info(undefined, {
            tpassword: p1,
        }, function() {
            stopLoading();
            context.user.user.tpassword = p1;
            alert2("资金密码修改成功！");
        });
    });
</script>